/// <reference path="layaui/layaUI.max.all.ts" />
/// <reference path="../libs/LayaAir.d.ts" />
/// <reference path="Global.ts" />
/// <reference path="ui/component/Panel.ts" />
/// <reference path="ui/component/DialogPanel.ts" />
/// <reference path="ui/component/View2.ts" />
/// <reference path="Manager/StageManager.ts" />
/// <reference path="Manager/UIManager.ts" />
/// <reference path="Manager/Web3Manager.ts" />
/// <reference path="Manager/ScreenManager.ts" />
/// <reference path="utils/Msg.ts" />
/// <reference path="data/HomePage.ts" />
/// <reference path="data/LocalSheetVo.ts" />
/// <reference path="type/MateMaskType.ts" />
/// <reference path="ui/map/MapModel.ts" />
/// <reference path="utils/LangUtils.ts" />
/// <reference path="type/LanguageType.ts" />
/// <reference path="utils/CookieUtils.ts" />
/// <reference path="utils/ResUtils.ts" />

// 程序入口ookieUtls
import WebGL = laya.webgl.WebGL;
import Stage = Laya.Stage;
import Handler = laya.utils.Handler;
import Pool = laya.utils.Pool;
import Texture = laya.resource.Texture;
import Bitmap = laya.resource.Bitmap;
import Browser = laya.utils.Browser;


class GameMain{

    constructor() {
        //初始化舞台宽高
        Laya.init(1863, 1080, WebGL);
        Laya.stage.alignH = Stage.ALIGN_CENTER;
        Laya.stage.alignV = Stage.ALIGN_MIDDLE;
        Laya.stage.scaleMode = Stage.SCALE_FIXED_WIDTH;
        if(Laya.Browser.onPC){
            Laya.stage.screenMode = Stage.SCREEN_HORIZONTAL;
        }else{
            Laya.stage.screenMode = Stage.SCREEN_VERTICAL;
        }
        Laya.stage.frameRate = Stage.FRAME_SLOW;
        //检测系统语言
        LangUtils.checkSystemLang();
    }

    /**
     * 初始化 加载
     */
    public init():void{
        window.onerror = function (a, b, c) {
            window.alert(a + "," + b + "," + c);
            console.log(a + "," + b + "," + c);
        };
        Laya.stage.on(Laya.Event.RESIZE,this,this.onResize);
        //预加载资源文件后执行回调
        Laya.loader.load(
            [
                {url:ResUtils.getLoadUrl("data/HomePage.bin"),type:Loader.BUFFER},
                {url:ResUtils.getLoadUrl("res/abi.json"),type:Loader.JSON},
                {url:ResUtils.getLoadUrl("res/atlas/10001.atlas"),type:Loader.ATLAS},
                {url:ResUtils.getLoadUrl("main/32.png"),type:Loader.IMAGE},
                {url:ResUtils.getLoadUrl("main/33.png"),type:Loader.IMAGE},
                {url:ResUtils.getLoadUrl("main/34.png"),type:Loader.IMAGE}
            ], Handler.create(this,this.onLoaded)
        );
    }

    //资源加载后回调
    private onLoaded(): void {
        Laya.Font.defaultFamily = Global.font;
        //初始化管理器
        LocalData.initDefinitionDic();
        LocalDataManager.getInstance().addLocolData("HomePage");
        StageManager.init();
        UIManager.init();
        Web3Manager.getInstance().init();
        //定时数据
        MapModel.getInstance().startExecContract();
        //显示主页面
        ScreenManager.showMainPage();
    }

    //舞台大小变更
    private onResize():void{
        StageManager.onResize();
        UIManager.onResize();
    }
}
new GameMain().init();
